package com.javabase.y2022.m04.day0422.v0035;

/**
 * @descriptions:
 * @author: Tom
 * @date: 2022/4/22 上午 09:55
 * @version: 1.0
 */
public class Solution {

    public static void main(String[] args) {
       int[] nums = new int[]{1,3,5,6};
       int target = 2;
       Solution s = new Solution();
        System.out.println(s.searchInsert(nums, target));
    }
    public int searchInsert(int[] nums, int target) {
        int right = nums.length - 1;
        int left = 0;
        int index = nums.length;
        while(left <= right){
            int mid = left + ((right - left) >> 1);
            if(nums[mid] >= target){
                index = mid;
                right = mid - 1;
            }else{
                left = mid + 1;
            }
        }
        return index ;
    }
}
